<template>
<h1>猜数字练习</h1>
  <input type="text" placeholder="请输入您猜的数字" v-model="num">
  <button @click="guess">猜一猜</button>
  <h4>您猜的结果是{{result}}</h4>
</template>

<script setup>
import {ref} from "vue";

let x = parseInt(Math.random()*100)+1;
console.log("打个小抄"+x)

const num = ref('');
const result = ref('');
const guess = () => {
  if(num.value.trim()==''){
    alert('请输入数字！');
    return;
  }
  if(num.value < x){
    result.value = '猜小了！';
  }else if(num.value > x){
    result.value = '猜大了！';
  }else{
    result.value = '恭喜猜对了！';
  }
}


</script>

<style scoped>

</style>